package com.vehicle.inspection.api

import chooongg.base.manager.app
import okhttp3.Interceptor
import okhttp3.Response
import java.io.IOException

class ReceivedCookiesInterceptor : Interceptor {
    @Throws(IOException::class)
    override fun intercept(chain: Interceptor.Chain): Response {
        val originalResponse = chain.proceed(chain.request())

        if (!originalResponse.headers("Set-Cookie").isEmpty()) {
            val cookies = HashSet<String>()

            for (header in originalResponse.headers("Set-Cookie")) {
                cookies.add(header)
            }
            val config = app.getSharedPreferences("config",0 ).edit()
            config.putStringSet("ccb_cookie", cookies)
            config.commit()
        }

        return originalResponse
    }
}